﻿/*
 * Twipler - Twitter Web Client with features.
 *  
 *  Copyright (C) 2009, 2010. Ian Quigley
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details. 
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Twipler.App.Machine;

namespace UnitTests.App.Parse
{
    public class ArrangeEntityMethodCallParser
    {
        private StaticMethodCall _call;

        public ArrangeEntityMethodCallParser(StaticMethodCall call)
        {
            _call = call;
        }

        public string Test
        {
            get
            {
                StringBuilder builder = new StringBuilder();
                CreateTest(builder, _call);
                return builder.ToString();
            }
        }

        private void CreateTest(StringBuilder builder, StaticMethodCall call)
        {
            builder.AppendFormat("{0}(", call.MethodName);

            if ((call.Params != null) && (call.Params.Count() > 0))
            {
                foreach (Variable param in call.Params)
                    CreateTestParam(builder, param);

                builder.Remove(0, builder.Length - 1);
            }

            builder.Append(")");
        }

        private void CreateTestParam(StringBuilder builder, Twipler.App.Machine.Variable param)
        {
            if (param.Value.GetType() == typeof (StaticMethodCall))
                CreateTest(builder, (StaticMethodCall) param.Value);
            else
                builder.AppendFormat("{0}", param.Value);

            builder.Append(",");
        }

        public void AssertSame(object result)
        {
            
        }
    }
}
